<template>
	<custom-layout custom-class="custom-layout">
		<wd-cell-group border v-if="contractDetails">
				
				<wd-cell title="合同编号" required>
					<view class="content">{{ contractDetails.contractNo }}</view>
				</wd-cell>
				<wd-cell title="施工模板" required>
					<view class="content"> 
						{{ stageModelName  }}
					</view>
				</wd-cell>
				<wd-cell title="纯设计">
					<view class="content">{{ dictionaryStore.analysis('is_type', contractDetails.isDesigner) }}</view>
				</wd-cell>
				<wd-cell title="是否有产品">
					<view class="content">{{ dictionaryStore.analysis('is_type', contractDetails.isProduct) }}</view>
				</wd-cell>
				<wd-cell title="合同总价">
					<view class="content">{{ contractDetails.contractPrice }}</view>
				</wd-cell>
				<wd-cell title="签约时间" required>
					<view class="content">{{ contractDetails.contractSigningTime?dayjs(contractDetails.contractSigningTime).format('YYYY-MM-DD HH:mm:ss'):'' }}</view>
				</wd-cell>
				<wd-cell title="合同开工时间" required v-if="['0'].includes(contractDetails.isDesigner)">
					<view class="content">{{ contractDetails.contractBeginTime?dayjs(contractDetails.contractBeginTime).format('YYYY-MM-DD'):'' }}</view>
				</wd-cell>
				<wd-cell title="合同完工时间" required v-if="['0'].includes(contractDetails.isDesigner)">
					<view class="content">{{ contractDetails.contractEndTime?dayjs(contractDetails.contractEndTime).format('YYYY-MM-DD'):'' }}</view>
				</wd-cell>
				<wd-cell title="实际开工时间" v-if="['0'].includes(contractDetails.isDesigner)">
					<view class="content">{{ contractDetails.actualBeginTime?dayjs(contractDetails.actualBeginTime).format('YYYY-MM-DD'):'' }}</view>
				</wd-cell>
				<wd-cell title="实际完工时间" v-if="['0'].includes(contractDetails.isDesigner)">
					<view class="content">{{ contractDetails.actualEndTime?dayjs(contractDetails.actualEndTime).format('YYYY-MM-DD'):'' }}</view>
				</wd-cell>
				<wd-cell title="合同文件">
					<view class="content">
						<template v-for="(file, index) in contractDetails.contractFile" :key="index">
            				<file-preview :file="file" />
          				</template>
					</view>
				</wd-cell>
				<wd-cell title="备注">
					<view class="content">{{ contractDetails.remark }}</view>
				</wd-cell>
				<!-- <wd-cell title="赠品">
					<view class="content"></view>
				</wd-cell>
				<wd-cell title="分期付款" required>
					<view class="content"></view>
				</wd-cell> -->
				
					
		</wd-cell-group>
		<!-- 空状态 -->
	  	<wd-status-tip v-else image="search" tip="暂无数据" />
		<stick-approve-dialog :order-id="props.orderId" approve-type="8" ref="stickyApproveDialogRef8"/>
    	<stick-approve-dialog :order-id="props.orderId" approve-type="15" ref="stickyApproveDialogRef15"/>
	</custom-layout>
</template>
<script setup>
	import {
		onMounted,
		reactive,
		ref,
		computed
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		useDictionaryStore,
		useUserStore
	} from '@/store/index.js'
	import {
		getContractByOrderId,
		getContractZheng,
		getEngineeringModel,
	} from '@/api/order/detail.js'
	import dayjs from 'dayjs';
	import stickApproveDialog from '@/packageA/components/stick-approve-dialog/stick-approve-dialog.vue';

	import FilePreview from '@/packageA/components/file-preview/file-preview.vue';
	// 字典仓库
	const dictionaryStore = useDictionaryStore()
	// 用户仓库
	const userStore = useUserStore()
const props = defineProps({
  // 订单id
  orderId: {
    type: Number,
    required: true
  },
  companyId: {
    type: Number,
    required: true
  },
  approveType: {
    type: String,
  }
});
// 合同详情
const contractDetails = ref(null);
// 整装合同id
const zzContractId = ref()
	
const handleGetContractZheng = (params) =>{
  getContractZheng(params).then(res=>{
    contractDetails.value=res
    console.log(contractDetails.value,'pppp');
    
  })
};	

	// 处理获取合同详情
const handleGetContractDetails = () => {
    uni.showLoading({
			mask: true
		})
  const params = {
    orderId: props.orderId,
  };
  getContractByOrderId(params)
    .then((data) => {
      // if (data) contractDetails.value = data.list[0] || {};
      if(data.total>0) {
        zzContractId.value = data.list[0].id
        handleGetContractZheng({id:data.list[0].id})
      } else {
        contractDetails.value = null;
      } 
    })
    .catch(({ message }) => {
      MessagePlugin.error(message);
    })
    .finally(() => {
	console.log(contractDetails.value,'22')
      uni.hideLoading();
    });
};
// 施工模板模板列表
const stageModelOptions = ref([]);
// 处理获取施工模板模板列表
const handleGetstageModelOptions = () => {
  const params = {
    companyId: props.companyId,
    pageSize: -1,
  };
  getEngineeringModel(params).then((data) => {
    stageModelOptions.value = data.list;
  });
};
// 计算属性，用于查找匹配的stageModel名称
const stageModelName = computed(() => {
  if (!contractDetails.value.stageModelId || stageModelOptions.value.length === 0) {
    return '';
  }
  const found = stageModelOptions.value.find(
    item => item.id === contractDetails.value.stageModelId
  );
  return found ? found.name : contractDetails.value.stageModelId;
});
const stickyApproveDialogRef8 = ref(null)
const stickyApproveDialogRef15 = ref(null)
onMounted(() => {
	handleGetstageModelOptions()
	handleGetContractDetails();
	if (props.approveType === '8')   stickyApproveDialogRef8.value.open();
  	if (props.approveType === '15')  stickyApproveDialogRef15.value.open();
})

</script>

<style lang="scss" scoped>
	// 自定义布局
	:deep(.custom-layout) {
		background: #F8F8F8;
	}

	// 返回按钮
	:deep(.submit-button) {
		margin: 32rpx;
	}
	.cell-title {
		font-size: 30rpx;
		font-weight: bold;
		margin: 24rpx;
		padding-left: 10rpx;
		position: relative;
	}
	.cell-title:before {
		content: "";
		position: absolute;
		left: -2px;
		top: 15%;
		height: 70%;
		width: 6rpx;
		background-color: #6a9cff;
	}
	
			
</style>